package medium;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class AplusBForPolynomials_1002 {
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		int num1=scanner.nextInt();
		int[] counts1=new int[num1];
		double[] nums1=new double[num1];
		for(int i=0;i<num1;++i) {
			counts1[i]=scanner.nextInt();
			nums1[i]=scanner.nextDouble();
		}
		int num2=scanner.nextInt();
		int[] counts2=new int[num2];
		double[] nums2=new double[num2];
		for(int i=0;i<num2;++i) {
			counts2[i]=scanner.nextInt();
			nums2[i]=scanner.nextDouble();
		}
		scanner.close();
		int index1=0,index2=0;
		List<Integer> counts=new ArrayList<Integer>();
		List<Double> values=new ArrayList<Double>();
		while(index1<num1&&index2<num2) {
			if(counts1[index1]!=counts2[index2]) {
				if(counts1[index1]>counts2[index2]) {
					counts.add(counts1[index1]);
					values.add(nums1[index1]);
					++index1;
				}
				else {
					counts.add(counts2[index2]);
					values.add(nums2[index2]);
					++index2;
				}
			}
			else {
				counts.add(counts1[index1]);
				values.add(Math.round((nums1[index1]+nums2[index2])* 10) / 10.0);
				++index1;
				++index2;
			}
		}
		while(index1!=num1) {
			counts.add(counts1[index1]);
			values.add(nums1[index1]);
			++index1;
		}
		while(index2!=num2) {
			counts.add(counts2[index2]);
			values.add(nums2[index2]);
			++index2;
		}
		System.out.print(counts.size());
		for(int i=0;i<counts.size();++i) {
			System.out.print(" "+counts.get(i)+" "+values.get(i));
		}
	}
}
